|
In computer programming, car and cdr ( or ) are primitive operations on cons cells (or "non-atomic S-expressions") introduced in the Lisp programming language. A cons cell is composed of two pointers; the ''car'' operation extracts the first pointer, and the ''cdr'' operation extracts the second. Thus, the expression (car (cons ''x'' ''y'')) evaluates to ''x'' , and (cdr (cons ''x'' ''y'')) evaluates to ''y'' .When cons cells are used to implement singly linked lists (rather than trees and other more complicated structures), the ''car'' operation returns the ''first'' element of the list, while ''cdr'' returns the ''rest'' of the list. For this reason, the operations are sometimes given the names ''first'' and ''rest'' or ''head'' and ''tail''. == Etymology == Lisp was originally implemented on the IBM 704 computer, in the late 1950s. The 704 hardware had special support for splitting a 36-bit machine word into four parts, an "address part" and "decrement part" of 15 bits each and a "prefix part" and "tag part" of three bits each. Precursors〔A Fortran-Compiled List-Processing Language ()〕 〔A Fortran-Compiled List-Processing Language; HTML transcription ()〕 to Lisp included functions: *''car'' (short for "Contents of the Address part of Register number"), *''cdr'' ("Contents of the Decrement part of Register number"), *''cpr'' ("Contents of the Prefix part of Register number"), and *''ctr'' ("Contents of the Tag part of Register number"), each of which took a machine address as an argument, loaded the corresponding word from memory, and extracted the appropriate bits. The 704 assembler macro for cdr was:〔Portions from NILS' LISP PAGES- (http://t3x.dyndns.org/LISP/QA/carcdr.html )〕A machine word could be reassembled by ''cons'', which took four arguments (''a'',''d'',''p'',''t''). The prefix and tag parts were dropped in the early stages of Lisp's design, leaving CAR, CDR, and a two-argument CONS. 抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)』 ■ウィキペディアで「CAR and CDR」の詳細全文を読む スポンサード リンク
|